package com.example.light.web.system.controller;

import com.alibaba.fastjson.JSON;
import com.example.light.web.system.entity.User;
import com.example.light.web.system.service.CuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Controller
public class CuserController {

    @Autowired
    private CuserService cuserService;

    /**
     *
     * 功能描述: 展示所有的用户角色部门信息
     *
     * @param: 
     * @return: 
     * @auther: 
     * @date:  
     */
    @RequestMapping("/roleUser.shtml")
    public String QueryAll(Model model,String rolename){
        return cuserService.QueryAll(model,rolename);
    }
    
    
    /**
     *
     * 功能描述: 显示用户个人信息窗口
     *
     * @param: 
     * @return: 
     * @auther: 
     * @date:  
     */
    @RequestMapping("userUpdateView.shtml")
    public String userUpdateView(Model model,String userId,String userName){
        model.addAttribute("userId",userId);
        model.addAttribute("userName",userName);
        return "system/userupdate";
     }
     
     /**
      *
      * 功能描述: 修改用户名或者密码
      *
      * @param: userUpdate.shtml
      * @return: 
      * @auther: 
      * @date:  
      */
     @RequestMapping("userUpdate.shtml")
     public String userUpdate(Model model,int userId,String userName, String userPass){
         cuserService.updata(model,userId,userName,userPass);
         return "system/userupdate";
     }
    
    /**
     *
     * 功能描述: 修改用户部门和角色信息
     *
     * @param: 
     * @return: 
     * @auther: 
     * @date:  
     */
    @RequestMapping("CuserUpload.shtml")
    //@RequestParam(value = "Udata")
    public String cuserUpload(Model model,@RequestParam(value = "UdataId")Integer[] ids,
                              @RequestParam(value = "UdataRole")String[] roles,
                              @RequestParam(value = "UdataDept")String[] depts)
    {
        return cuserService.Change(model,ids,roles,depts);
    }

    /**
     *
     * 功能描述: 删除用户
     *
     * @param:
     * @return:
     * @auther:
     * @date:
     */
    @RequestMapping("CuserDelete.shtml")
    public String cuserDelete(Model model,@RequestParam(value = "ids")Integer[] ids)
    {
        return cuserService.Deleting(ids);
    }



    /**
     *
     * 功能描述: 查询用户
     *
     * @param:
     * @return:
     * @auther:
     * @date:
     */
    @RequestMapping("CuserSelect.shtml")
    public String cuserSelect(Model model,@RequestParam(value = "selectname")String name)
    {
        return cuserService.selectbyname(model,name);
    }

}
